#include <arpa/inet.h>
#include <stdint.h>

#include "byteorder.hpp"

namespace Private
{
	template<>
	void convert<4, true>(int &val)
	{
		// static_assert
		char dummy[sizeof(uint32_t) == sizeof(int)]; (void)dummy;
		reinterpret_cast<uint32_t&>(val) = htonl(reinterpret_cast<const uint32_t&>(val));
	}
	
	template<>
	void convert<4, false>(int &val)
	{
		// static_assert
		char dummy[sizeof(uint32_t) == sizeof(int)]; (void)dummy;
		reinterpret_cast<uint32_t&>(val) = ntohl(reinterpret_cast<const uint32_t&>(val));
	}

	template<>
	void convert<2, true>(short &val)
	{
		// static_assert
		char dummy[sizeof(uint32_t) == sizeof(int)]; (void)dummy;
		reinterpret_cast<uint16_t&>(val) = htons(reinterpret_cast<const uint16_t&>(val));
	}

	template<>
	void convert<2, false>(short &val)
	{
		// static_assert
		char dummy[sizeof(uint32_t) == sizeof(int)]; (void)dummy;
		reinterpret_cast<uint16_t&>(val) = ntohs(reinterpret_cast<const uint16_t&>(val));
	}

	template<>
	void convert<1, true>(char &)
	{
		// static_assert
		char dummy[sizeof(uint32_t) == sizeof(int)]; (void)dummy;
		// do nothing
	}

	template<>
	void convert<1, false>(char &)
	{
		// static_assert
		char dummy[sizeof(uint32_t) == sizeof(int)]; (void)dummy;
		// do nothing
	}

}
